package com.small.nine.wxmp.domain.bean.wx.msg;

import com.small.nine.wxmp.common.constant.WxConstant;
import com.small.nine.wxmp.utils.wx.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 回复文本消息
 *
 * @author sheng_zs@126.com
 * @date 2021-08-02 17:22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@XStreamAlias("xml")
public class WxTextMsgBean extends WxOutMsgBaseBean {
    private static final long serialVersionUID = 1L;

    /**
     * 回复的消息内容（换行：在content中能够换行，微信客户端就支持换行显示）
     */
    @XStreamAlias("Content")
    private String content;

    @Override
    public String toXml() {
        return XmlUtils.beanToXml(this);
    }

    /**
     * 初始化
     *
     * @param toUser     接收者，openID
     * @param fromUser   发送者
     * @param createTime 时间戳
     * @param content    文本信息
     * @return {@link WxTextMsgBean}
     */
    public static WxTextMsgBean getInstance(String toUser, String fromUser, Long createTime, String content) {
        WxTextMsgBean msgBean = new WxTextMsgBean();
        msgBean.setToUserName(toUser);
        msgBean.setFromUserName(fromUser);
        msgBean.setMsgType(WxConstant.MSG_TYPE_TEXT);
        msgBean.setCreateTime(createTime);
        msgBean.setContent(content);
        return msgBean;
    }
}
